<%@ page language="java" session="true" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<jsp:include page="../common/framework/header.jsp" />
<style>
	body{
		font-size:12px;color:#333;font-family:微软雅黑;background-color: #fff;
	}
  .form-inline .form-control {
    width: 100%;
	}
	.checkbox input[type=checkbox], .checkbox-inline input[type=checkbox], .radio input[type=radio], .radio-inline input[type=radio] {
    margin-top: 2px;
}
.checkbox, .radio {
    margin-top: 5px;
}
</style>

	<div class="container-fluid" style="padding-right:30px;padding-left:10px;padding-top:40px;" id="createBugDiv">
    <form id ="createBugForm" enctype="multipart/form-data">
<!--     	<div class = "form-inline row"> -->
<!-- 	    	<div class = "form-group col-sm-12 col-xs-12" style="padding-left:13px;"> -->
<!-- 	            <label class="col-xs-1" style="padding:6px 0 0 0;text-align:right;">jira项目:</label> -->
<!-- 	            <div class="col-xs-11" style="padding-right:0;"> -->
<!-- 					<input type = "text" class="  form-control"  id="email" name = "email">     -->
<!-- 				</div> -->
<!-- 			</div> -->
<!-- 		</div> -->
    	<div class = "form-inline row" >
         	<div class="form-group col-sm-6 col-xs-6" >
            	<label class="col-xs-2" style="padding:6px 0 0 0;text-align:right;"><font color=red>*</font>主题:</label>
            	<div class="col-xs-10" style="padding-right:0;">
					<input type = "text" class="  form-control"   placeholder="请输入" id="summary" name="summary">
				</div>
         	</div>
         	<div class = "form-group col-sm-6 col-xs-6" >
            	<label class="col-xs-2" style="padding:6px 0 0 0;text-align:right;">问题类型:</label>
            	<div class="col-xs-10" style="padding-right:0;">
					<select class="form-control" data-width="100%">
                        <option>BUG</option>
                    </select>
				</div>
			</div>
		</div>
		<div class = "form-inline row" >
	    	<div class = "form-group col-sm-12 col-xs-12" style="padding-left:13px;">
	            <label class="col-xs-1" style="padding:6px 0 0 0;text-align:right;">描述:</label>
	            <div class="col-xs-11" style="padding-right:0;">
					<textarea class="form-control" style = "resize: vertical;" rows="4"
            		id = "description" name = "description"></textarea>
				</div>
			</div>
		</div>
		<div class = "form-inline row" >
         	<div class="form-group col-sm-6 col-xs-6" >
            	<label class="col-xs-2" style="padding:6px 0 0 0;text-align:right;">报告人:</label>
            	<div class="col-xs-10" style="padding-right:0;">
					<select class="form-control" data-width="100%" id="reporter" name="reporter">
                    </select>
				</div>
         	</div>
         	<div class = "form-group col-sm-6 col-xs-6" >
            	<label class="col-xs-2" style="padding:6px 0 0 0;text-align:right;">经办人:</label>
            	<div class="col-xs-10" style="padding-right:0;">
					<select class="form-control" data-width="100%" id="assignee" name="assignee">
                    </select>
				</div>
			</div>
			</div>
			<div class = "form-inline row" >
	         	<div class="form-group col-sm-6 col-xs-6" >
	            	<label class="col-xs-2" style="padding:6px 0 0 0;text-align:right;">严重级别:</label>
	            	<div class="col-xs-10" style="padding-right:0;">
						<select class="form-control" data-width="100%" id="severityLevel" name="severityLevel">
	                        <option value="1 - 严重">严重</option>
	                        <option value="2 - 高">高</option>
	                        <option value="3 - 中">中</option>
	                        <option value="4 - 低">低</option>
	                    </select>
					</div>
	         	</div>
	         	<div class = "form-group col-sm-6 col-xs-6" >
	            	<label class="col-xs-2" style="padding:6px 0 0 0;text-align:right;">优先级:</label>
	            	<div class="col-xs-10" style="padding-right:0;">
						<select class="form-control" data-width="100%" id="priority" name="priority">
	                        <option>Highest</option>
	                        <option>High</option>
	                        <option>Medium</option>
	                        <option>Low</option>
	                        <option>Lowest</option>
	                    </select>
					</div>
				</div>
			</div>
			<div class = "form-inline row" >
	    	<div class = "form-group col-sm-12 col-xs-12" style="padding-left:13px;">
	            <label class="col-xs-1" style="padding:6px 0 0 0;text-align:right;">附件:</label>
	            <div class="col-xs-11" style="padding-right:0;">
					<input type="file" class="  form-control" id="files" name="files"   class="file"  style="width:100%" multiple="multiple" onchange="fileChange(this);">
				</div>
			</div>
		</div>
		<input type ="hidden"   id="testcaseId" name="testcaseId">
    </form>
</div>
	<jsp:include page="../common/framework/script.jsp" />
    <script type="text/javascript">
  //给弹框添加回车提交事件
    $(function(){ 
    	$(document).keydown(function(event){ 
	    	if(event.keyCode==13){
	    		window.event.returnValue = false;
	    		submit();
	    	} 
    	}); 
});

    $(function(){
    	/*表单验证  */
    	//表单验证
    		 $('#createBugForm').bootstrapValidator({
    	   		   message: 'This value is not valid',
    	           feedbackIcons: {
    	        	   valid:'glyphicon glyphicon-ok',
    	        	   invalid:'glyphicon glyphicon-remove',
    	        	   validating:'glyphicon glyphicon-refresh'
    	           },
    	           excluded: [':disabled'],
    	            fields: {
    	            	summary :{
    						message : '主题名称验证失败',
    						validators : {
    							notEmpty : {//非空验证：提示消息
    								message : '主题名称不能为空'
    							},
    							stringLength: {/*长度提示*/
    							    min: 1,
    							    max: 100,
    							    message: '主题名称长度必须在1到100个字之间'
    							   }
    						}
    					}

    	               }
    	        });
    	})
    var testcaseId = parent.testcaseId;
    console.log("testcaseId:"+testcaseId);
    $("#testcaseId").val(testcaseId);
    getTcStep();
    getAuthUser();
    function getTcStep(){
    	$.ajax({
    	    type : "get",
    	    async: false,
    	    url : path+'/testCaseController/getTcStep?testcaseId='+testcaseId,//找到controller里相应的方法
    	    beforeSend: function(XMLHttpRequest){

        	},
    	    success : function(dataList) {
    	    	console.log("dataList: "+JSON.stringify(dataList));
    	    	var remarkStr = "【故障复现步骤】\n";
    	    	$(dataList).each(function(index,data){
    	    		remarkStr += "测试步骤"+data.stepNumber+":\n"+data.action+"\n";
		    	});
				$('#description').text(remarkStr);
    	    },
    	    complete: function(XMLHttpRequest, textStatus){


        	}
    	   });

    };

    var projectId = '${currentProjectId}';
    var userAccount = '${userAccount}';
    var userId = '${userId}';
    var userName = '${userName}';
//     ${currentProjectId}
//     ${userAccount}
//     ${userId}
//     ${userName}
    console.log("projectId: "+projectId);
    console.log("userAccount: "+userAccount);
    console.log("userId: "+userId);
    console.log("userName: "+userName);

    function getAuthUser(){
    	$.ajax({
	        type : "post",
	        url : path+'/testCaseController/getAssignableUser',//找到controller里相应的方法
	        data : {}, //把数组的值赋给data，把上面的param改为data,这里就能直接去掉
	        dataType : "json",//根据数据类型选择text、jason等
	        success : function(dataList) { 
	        	//加载报告人下拉列表
		    	$("#reporter").html("");
		    	$(dataList).each(function(index,data){
		    		$("#reporter").append("<option value="+data.userAccount+">"+data.userName+"</option>");
				});
		    	//加载经办人下拉列表
		    	$("#assignee").html("<option value=''>请选择</option>");
		    	$(dataList).each(function(index,data){
		    		$("#assignee").append("<option value="+data.userAccount+">"+data.userName+"</option>");
				});
	        }
	       });

    };
    //保存事件触发
    function submit(){
    	var bootstrapValidator = $("#createBugForm").data('bootstrapValidator').validate();
    	if(bootstrapValidator.isValid()){
    		$("#createBugForm").ajaxSubmit({
    			type : "POST",
    			url : path+'/testCaseController/createJiraBug',
    			processData:false,
    			dataType : 'json',
    	        success : function(data) {
    	        	if(data.result == true){
    	        		var relationId = data.relationId;
    	        		var destinationType = data.destinationType;
        	        	var name = data.name;
        	        	var relationType = data.relationType;
        	        	//在所有连接tab页中增加一条数据 
        	        	parent.$("#linkTb").bootstrapTable('append', {"relationId":relationId,"relationTypeId":"4","destinationId":"","destinationType":destinationType,"name":name,"relationType":relationType,"ifInner":"false"});	        		
    	        		
    	        		parent.layer.closeAll();
    	        		parent.toast.success('操作成功！','成功提示');
    	        	}else{
    	        		toast.error('操作失败！','失败提示');
    	        	}
    	        }
    		});
    	}
    	

    };

    
  //文件类型和大小的控制
    var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
    function fileChange(target,id) {
        var fileSize = 0;
//         var filetypes =[".xls",".xlsx"];
        var filepath = target.value;
        var filemaxsize = 1024*10;//10M
        if(filepath){
            var isnext = false;
            var fileend = filepath.substring(filepath.lastIndexOf("."));
//             if(filetypes && filetypes.length>0){
//                 for(var i =0; i<filetypes.length;i++){
//                     if(filetypes[i]==fileend){
//                         isnext = true;
//                         break;
//                     }
//                 }
//             }
//             if(!isnext){
// //	                alert("不接受此文件类型！");
//                 toast.info ('只接受".xls",".xlsx"类型的文件！','信息提示'); 
//                 target.value ="";
//                 return false;
//             }
        }else{
            return false;
        }
        if (isIE && !target.files) {
            var filePath = target.value;
            var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
            if(!fileSystem.FileExists(filePath)){
                toast.info ('附件不存在，请重新输入！','信息提示'); 
                return false;
            }
            var file = fileSystem.GetFile (filePath);
            fileSize = file.Size;
        } else {
            fileSize = target.files[0].size;
        }

        var size = fileSize / 1024;
        if(size>filemaxsize){
            toast.info ('附件大小不能大于'+filemaxsize/1024+'M！','信息提示'); 
            target.value ="";
            return false;
        }
        if(size<=0){
            toast.info ('附件大小不能为0M！','信息提示'); 
            target.value ="";
            return false;
        }
    }
    
    </script>
<jsp:include page="../common/framework/footer.jsp" />